<?php
  if (!defined('XOOPS_ROOT_PATH')) { exit(); }
  
if ( $op == 'restart' ) {
  $poll = new XoopsPoll($_GET['poll_id']);
  $poll_form = new XoopsThemeForm(_AM_RESTARTPOLL, 'poll_form', 'index.php');
  $expire_text = new XoopsFormText(_AM_EXPIRATION.'<br /><small>'._AM_FORMAT.'<br />'.sprintf(_AM_CURRENTTIME, formatTimestamp(time(), 'Y-m-d H:i:s')).'</small>', 'end_time', 20, 19, formatTimestamp(time()+604800, 'Y-m-d H:i:s'));
  $poll_form->addElement($expire_text);
  $notify_yn = new XoopsFormRadioYN(_AM_NOTIFY, 'notify', 1);
  $poll_form->addElement($notify_yn);
  $reset_yn = new XoopsFormRadioYN(_AM_RESET, 'reset', 0);
  $poll_form->addElement($reset_yn);
  $op_hidden = new XoopsFormHidden('op', 'restart_ok');
  $poll_form->addElement($op_hidden);
  $poll_id_hidden = new XoopsFormHidden('poll_id', $poll->getVar('poll_id'));
  $poll_form->addElement($poll_id_hidden);
  $submit_button = new XoopsFormButton('', 'poll_submit', _AM_RESTART, 'submit');
  $poll_form->addElement($submit_button);

  xoops_cp_header();
  echo '<h4>'._AM_POLLCONF.'</h4>';
  $poll_form->display();
  xoops_cp_footer();
} elseif ( $op == 'restart_ok' ) {
  $poll = new XoopsPoll($_POST['poll_id']);
  if ( !empty($_POST['end_time']) ) {
    $end_time = userTimeToServerTime(strtotime($_POST['end_time']), $xoopsUser->timezone());
    $poll->setVar('end_time', $end_time);
  } else {
    $poll->setVar('end_time', time() + (86400 * 10));
  }
  if ( $_POST['notify'] == 1 && $end_time > time() ) {
    $poll->setVar('mail_status', POLL_NOTMAILED);
  } else {
    $poll->setVar('mail_status', POLL_MAILED);
  }
  if ( $_POST['reset'] == 1 ) {
    XoopsPollLog::deleteByPollId($poll->getVar('poll_id'));
    XoopsPollOption::resetCountByPollId($poll->getVar('poll_id'));
  }
  if (!$poll->store()) {
    echo $poll->getHtmlErrors();
    exit();
  }
  $poll->updateCount();
  include_once XOOPS_ROOT_PATH.'/class/template.php';
  xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
  redirect_header('index.php',1,_AM_DBUPDATED);
}
?>